package com.jianhua.backend.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jianhua.backend.domain.dto.PackageSQDto;
import com.jianhua.backend.domain.entity.MealPackages;
import com.jianhua.backend.domain.entity.PackageSQ;
import com.jianhua.backend.mapper.MealPackagesMapper;
import com.jianhua.backend.mapper.PackageSQMapper;
import com.jianhua.backend.service.MealPackagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import java.util.Collections;


/**
 * <p>
 * 存储预设套餐信息，如主菜+配菜+饮品组合 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-07-02
 */
@Service
public class MealPackagesServiceImpl extends ServiceImpl<MealPackagesMapper, MealPackages> implements MealPackagesService {

    @Autowired
    private MealPackagesMapper mealPackagesMapper;

    @Autowired
    private PackageSQMapper packageSQMapper;

    @Autowired
    public MealPackagesServiceImpl(MealPackagesMapper mealPackagesMapper) {
        this.mealPackagesMapper = mealPackagesMapper;
    }

    @Override
    public List<MealPackages> getAllPackages() {
        return this.list();
    }

    @Override
    public MealPackages getPackageById(Integer packageId) {
        return this.getById(packageId);
    }

    @Override
    public void createPackage(MealPackages mealPackage) {
        this.save(mealPackage);
    }

    @Override
    public void updatePackage(MealPackages mealPackage) {
        this.updateById(mealPackage);
    }

    @Override
    public void deletePackage(Integer packageId) {
        this.removeById(packageId);
    }

    @Override
    public List<PackageSQ> getMealPackages(PackageSQDto packageSQDto) {

        LambdaQueryWrapper<PackageSQ> queryWrapper = new LambdaQueryWrapper<>();
        if (packageSQDto.getYear() != null) {
            queryWrapper.eq(PackageSQ::getYear, packageSQDto.getYear());
        }
        if (packageSQDto.getQuarter() != null) {
            queryWrapper.eq(PackageSQ::getQuarter, packageSQDto.getQuarter());
        }

        return packageSQMapper.selectList(queryWrapper);
    }
}
